﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SetTemplateAndKeywords.CApSetTemplateAndKeywordsEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Olp;


namespace DnProcessSimulateCommands.SetTemplateAndKeywords;

public class CApSetTemplateAndKeywordsEnabler : ITxCommandEnabler
{
  private bool CheckEnable()
  {
    bool flag = false;
    TxObjectList items = TxApplication.ActiveSelection.GetItems();
    if (items != null && ((Collection<ITxObject>) items).Count > 0)
    {
      if (((Collection<ITxObject>) items).Count == 1 && ((Collection<ITxObject>) items)[0] is TxRobot)
      {
        flag = true;
      }
      else
      {
        flag = true;
        TxOlpControllerUtilities controllerUtilities = new TxOlpControllerUtilities();
        TxRobot txRobot1 = (TxRobot) null;
        TxRobot txRobot2 = (TxRobot) null;
        foreach (ITxObject itxObject in (Collection<ITxObject>) items)
        {
          if (itxObject is ITxOperation)
            txRobot2 = controllerUtilities.GetRobot(itxObject as ITxOperation);
          if (TxRobot.op_Equality(txRobot1, (ITxObject) null) && TxRobot.op_Inequality(txRobot2, (ITxObject) null))
            txRobot1 = txRobot2;
          if (TxRobot.op_Equality(txRobot2, (ITxObject) null) || TxRobot.op_Inequality(txRobot1, (ITxObject) txRobot2))
          {
            flag = false;
            break;
          }
        }
      }
    }
    return flag;
  }

  public bool Enable => this.CheckEnable();
}
